<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>帐号管理</title>
<link href="/stylesheets/survey_public.css" rel="stylesheet" type="text/css" />
<link href="/stylesheets/jquery.multiselect.css" rel="stylesheet" type="text/css" />
<link href="/stylesheets/jquery-ui.custom.css" rel="stylesheet" type="text/css" />
<style type="text/css">
#header{ width:885px; float:left; height:120px; background:url(/images/user/report_list/header.jpg) no-repeat;}
#header ol li{ width:670px; height:92px; margin-top:25px; float:left;}

#header ul{ width:170px; height:84px; float:left; margin-top:10px;}
#header ul li{line-height:38px; font-size:14px; color:#FFFFFF; text-align:right;}
#header ul li a{ color:#FFFFFF; font-size:12px; padding-right:20px;}

#content_header{ width:870px;height:20px;margin:5px 0 5px 5px; float:left;border-bottom:1px solid #D7E2EA;}

#content{ width:885px; height:600px; float:left;}
#text{ width:134px; height:18px; border:1px solid #a5acb2; margin-top:10px;}
.back{ width:102px; height:35px; float:right; padding-right:20px; margin-top:10px;}
.left{ width:170px; height:420px; float:left; background:url(/images/user/report_list/leftbg.jpg) no-repeat;margin-top:5px;}
.left01{ width:144px; margin:16px 0 0 10px; display:inline; border-bottom:1px dashed #0074c6; float:left;}
#text{ width:70px; height:16px; border:1px solid #0074c6;}
.left02{ width:144px;  margin-top:12px; float:left; margin-left:12px; display:inline; overflow:hidden; }
.right{ width:710px; float:right; margin-top:5px;margin-left: 5px;}

#content_1{ width:885px; float:left; }
.back{ width:102px; height:35px; float:right; padding-right:20px; margin-top:10px;}
.c_left{ width:170px; height:420px; float:left; background:url(/images/user/report_list/leftbg.jpg) no-repeat;margin-top:5px;}
.c_left01{ width:144px; height:230px; margin:16px 0 0 10px; display:inline; border-bottom:1px dashed #0074c6; float:left;}
#text, #text1{ width:70px; height:16px; border:1px solid #0074c6;}

#text2{ width:70px; height:16px; border:1px solid #0074c6;margin:3px 0 3px 8px;}
.c_left02{ width:144px; height:250px; margin-top:12px; float:left; margin-left:12px; display:inline; overflow:hidden; }
.c_right{ width:710px; float:right; margin-top:5px;margin-left: 5px;}
#time-field{ width:80px; height:12px; border:1px solid #0074c6;}

#footer{ width:100%; height:200px; float:left; background:url(/images/user/report_list/footer.jpg) no-repeat; text-align:center; color:#295c72;}
#footer h1{ margin-top:100px;}
.create-submit {background-color:#368ED5; color:white; border:1px solid #A8C5CF;}
.validation-advice{
	margin: 5px 0;
	padding: 5px;
	background-color: #FF3300;
	color : white;
	font-weight: bold;
}
.form-item {margin-top:5px; margin-bottom:5px;}
</style>

</head>
<body>
<div id="page">
	<div id="header">
		<ol>
		<li id="title-text">帐号管理</li>
		</ol>
		<ul>
        <li id="org-text"><%=current_user.name%></li>
		    <li><a href="/login/logout">安全退出</a></li>
		</ul>
	</div>
	   <div id="content_header" >
	     <a href="/user/info_manage/accounts"   
	     style="margin-left:20px; background-color: #378FD6; color:white; padding:5px 5px 4px 5px; overflow:hidden;">
	      账户管理</a>
	     <a href="/user/info_manage/accounts?wh=main"
	        style="margin-left:10px;  ">
	      机构信息</a>
	   </div>
	   <div id="content_1" style="display:none">
	   <div class="c_left"></div>
	   <div class="c_right"></div>
	   </div>
     <div id="content">
    <div class="left">
        	<div class="left01">
        	<span style="margin:0 0 0 20px;color:#29506F;">创建一个帐号</span><br />
     <%form_for(:temp_user , :url=>{ :action=>"create_account"} , :html=>{ :class=>"required-validate" , :id=>"create_account" })  do |f| %>
                <div class="form-item">
                  登录名：&nbsp;
                  <input type="text"  id="text" name="temp_user[name]" class="required"  style="margin:0 0 0 3px;"/><br />
                </div>

                <div class="form-item">
                  <span style="padding:6px 6px 6px 0px;">所属文件夹：</span>
                  <select name="temp_user[folder_id]" id="temp_user_folder"
                   style="width:140px; height:18px; border:1px solid #a5acb2; margin-top:5px;" >
                  <option value=“0” selected="selected" >暂不指定</option>
                  <% @all_folders.each do |folder|%>
                   <option value='<%=folder.id%>'><%=folder.name%></option>
                  <% end %>
                   </select>
                </div>
                
                <div class="form-item">
                  <span></span>
                  <select name="survey_ids[]" id="survey-selector-a" multiple="multiple" size="5" style="width:80px;">
                    <option value=""></option>
                    <% @all_survey.each do |survey|%>
                      <option value='<%=survey.id%>' title="<%=survey.name%>"><%=survey.name%></option>
                    <% end %>
                   </select>
                </div>
                
                <div class="form-item">
                  <span style="padding:6px 6px 6px 0px;">有效期：</span>
                  <%= text_field 'temp_user', 'last_time', :onClick=>"SelectDate(this,'yyyy-MM-dd')" , :id=>"text",:size=>10%><br />
                </div>
                <div class="form-item">
                  <input type="submit" value="创建" class="create-submit"></input><br/><br/><br/>
                </div>
    <% end %>            

                
           </div> <!--div .left01 结束-->
            <div class="left02">
              <br/>
    <span style="margin:0 0 0 20px;color:#29506F;">批量添加帐号:</span><br />
      <%form_for(:temp_user , :url=>{ :action=>"create_accounts"} , :html=>{ :class=>"required-validate" , 
      :id=>"create_accounts" })  do |f| %>
    <div class="form-item">
    登录名：&nbsp;
    <input type="text" size="12"  id="text2"name="temp_user[name]" class="required"/><br />
    </div>
    
    <div class="form-item">
    帐号数目：
    <input type="text" id="text1" name="number" size="14"
     class="required validate-integer" /><br />
    </div>
    
     <div class="form-item">
   <span style="padding:6px 6px 6px 0px;">所属文件夹：</span>
   </div>
   <div class="form-item">
    <select name="temp_user[folder_id]" id="temp_user_folder2"
     style="width:140px; height:18px; border:1px solid #a5acb2; margin-top:2px;" >
    <option value=“0” selected="selected" >暂不指定</option>
    <% @all_folders.each do |folder|%>
     <option value='<%=folder.id%>'><%=folder.name%></option>
    <% end %>
     </select><br />
     </div>

    <div class="form-item">
      <span></span>

      <select name="survey_ids[]" id="survey-selector-b" multiple="multiple" size="5" style="width:80px;">
        <option value=""></option>
        <% @all_survey.each do |survey|%>
          <option value='<%=survey.id%>' title="<%=survey.name%>"><%=survey.name%></option>
        <% end %>
       </select>
    </div>
    
     <div class="form-item">
     有效期：&nbsp;&nbsp;
     <%= text_field 'temp_user', 'last_time', :onClick=>"SelectDate(this,'yyyy-MM-dd')" , :id=>"text", :size=>10%><br />
     </div>
     <div class="form-item">
     <input type="submit" value="创建" class="create-submit"></input>
     </div>
    <% end %>

    </div>
    </div>
    <div class="right" id="right">

      <div id="right_top" style=" width:710px; float:right; height:20px;margin-top:5px;">        
             <font color="red" style="float:left;margin:3px 0 0 10px;"><%=flash[:notice] %></font>
            <a href="/user/test/home"  
            style=" float:right; margin:0 15px 0 0;"><img src="/images/back.png" width="88" height="27" /></a>
       </div>
      <div style=" width:710px; float:right; margin-top:10px;" >
        <div style="margin-bottom:10px;">
            <a href="javascript:;" onclick="copy_all();" style="margin-left:15px;"> 复制所选帐号</a>&nbsp;&nbsp;
            <a href="javascript:;" onclick="del();"> 删除</a>&nbsp;&nbsp;
            <a href="javascript:;" onclick="show_update();"> 变更有效期</a>
           <span id="update_time" style="display:none;">
           <%= text_field 'temp_user', 'update_time', :onClick=>"SelectDate(this,'yyyy-MM-dd')" ,
           :id=>"time-field", :size=>10, :style => "height:18px;" %>
             <input type="button"  value="更改" onclick="extend_time();" class="create-submit"></input>
           </span>
            <br/>

        </div>
        
         <table width="700" border="0" cellpadding="0" cellspacing="0" style="border-left:1px solid #dadada; border-top:1px solid #dadada;">    
           <tr width="700" >
               <td width="20"  background="/images/user/report_list/bg_03.jpg" height="30"  valign="middle" 
               style=" border-right:1px solid #dadada;">
               <input type="checkbox" name="all_seect" class="all_select" 
               onclick="select_all(this);" style="margin-left:17px; display:inline;" />
            </td>  
            <td width="100" style="border-right:1px solid #dadada; " 
            background="/images/user/report_list/bg_03.jpg" height="30" align="center" valign="middle" >登录名</td>
            <td width="80" style="border-right:1px solid #dadada; " 
            background="/images/user/report_list/bg_03.jpg" height="30" align="center" valign="middle" >密码</td>
           <td width="80" style="border-right:1px solid #dadada; " 
           background="/images/user/report_list/bg_03.jpg" height="30" align="center" valign="middle" >文件夹</td>
           <td width="160" style="border-right:1px solid #dadada; " 
           background="/images/user/report_list/bg_03.jpg" height="30" align="center" valign="middle" >量表</td>
            <td width="140" style="border-right:1px solid #dadada; " 
             background="/images/user/report_list/bg_03.jpg" height="30" align="center" valign="middle" >有效期至</td>
            <td width="50" style="border-right:1px solid #dadada; " 
            background="/images/user/report_list/bg_03.jpg" height="30" align="center" valign="middle" >状态</td>
             <td width="50" style="border-right:1px solid #dadada; " 
            background="/images/user/report_list/bg_03.jpg" height="30" align="center" valign="middle" >报告</td>
            <!--td width="100" style="border-right:1px solid #dadada; " 
            background="/images/user/report_list/bg_03.jpg" height="30" align="center" valign="middle" >&nbsp;</td-->
           </tr>
      <% @tempusers.each do |tu| %>
       <tr width="600" >
         <td width="50"  height="30" align="center" valign="middle" 
         style="border-bottom:1px solid #dadada; border-right:1px solid #dadada;">
           <input type="checkbox"class="check_boxes" id="check_boxes"  
           alt="用户名:<%=tu.name%> ,  密码:<%=tu.password%>       ; " 
           value="<%=tu.id%>"
           style="margin:7px 0 0 0;">
           </input> 
          </td>
          <td  height="30" align="center" valign="middle" style="border-right:1px solid #dadada; border-bottom:1px solid #dadada" >
         <% if tu.record_id != nil %>
         <a href="/user/reports/show_report/<%=tu.record_id%>">
         <%=tu.name%>
         </a>
         <% else %>
         <%=tu.name%>
         <% end %>
         </td>
         <td height="30" align="center" valign="middle" style="border-right:1px solid #dadada; border-bottom:1px solid #dadada" >
         <%=tu.password%></td>
         <td  height="30" align="center" valign="middle" style="border-right:1px solid #dadada; border-bottom:1px solid #dadada" >
          <% if tu.folder_id >0 %>
         <%=tu.folder.name%><% else %>无
         <% end %></td>
         <td  height="30" align="center" valign="middle" style="border-right:1px solid #dadada; border-bottom:1px solid #dadada"  onmouseover="$('#pop<%=tu.id%>').show();" onmouseout="$('#pop<%=tu.id%>').hide()">
         <%=tu.survey_ids == nil ? '无' : "共#{tu.survey_ids.split(',').size()}个可用量表"%>
         <div id="pop<%=tu.id%>" style="display:none;">
           <% if tu.survey_ids %>
             <% for sid in tu.survey_ids.split(',') %>
               <%= Survey.find(sid.to_i).name %><br/>
             <% end %>
           <% end %>
         </div>
         </td>
         <td height="30" align="center" valign="middle" style="border-right:1px solid #dadada; border-bottom:1px solid #dadada" >
         <%=tu.last_time.strftime('%Y年%m月%d日')%> &nbsp;&nbsp;
         </td>
          <td height="30" align="center" valign="middle" style="border-right:1px solid #dadada; border-bottom:1px solid #dadada" >
         <% if tu.used == true %> 已测 <% else %> 未测 <% end %>
         </td>
         <td height="30" align="center" valign="middle" style="border-right:1px solid #dadada; border-bottom:1px solid #dadada" >
         <% if tu.record_id != nil %>
         <a href="/user/reports/show_report/<%=tu.record_id%>"> 查看 </a>
         <% else %>   无<% end %>
        </td>
   <% end %>
          </table>
     </div><!--列表结束-->
        <div style="margin-left:150px; ">
        <% if @tempusers.page_count > 1%>
           <%if params[:page]==nil
              cur_page=1 else cur_page=params[:page].to_i
              end %>
            <div class="pagination">
            <% if  cur_page >1%>
            <a href="/user/info_manage/accounts?&page=<%=params[:page_num].to_i-1%>"><span>上一页</span></a>|
            <% else %>
            <span>上一页|</span>
            <% end %>
            <% for i in 1..@tempusers.page_count%>
            <% if i==params[:page].to_i %>
            <span>&nbsp;<%=i%>&nbsp;|</span>
            <% else %>
            <a href="/user/info_manage/accounts?&page=<%=i%>"><span>&nbsp;<%=i%>&nbsp;</span></a>|
            <% end %>
            <% end %>
            <% if @tempusers.page_count > 1 && cur_page < @tempusers.page_count %> 
            <a href="/user/info_manage/accounts?&page=<%=cur_page+1%>"><span>下一页</span></a>
            <% else %>
            <span>下一页</span>
            <% end %>
            </div>
            <% end %>
         </div>

     </div>
      </div>
        <div class="back">
          <a href="/user/test/home"><img src="/images/back.png" width="88" height="27" /></a>
        </div>
    </div>

  <div id="footer">
<h1>北京心嘉源咨询有限公司 CopyRight © www.iyaoi.cn 2009</h1>
</div>

  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"></script>
  <script src="/javascripts/jquery/jquery.multiselect.js" type="text/javascript"></script>

  <script src="/javascripts/WebCalendar.js" type="text/javascript"></script>
  <script type="text/javascript">
   function copy(user,passwd){
   var copy="用户名："+user+"  密码： "+passwd;
   copy_clip(copy);
   }

  function copy_all(){
    var messages="";
    $(".check_boxes").each(function(i) {
      if (this.checked){
        messages += this.alt;
      }
    });
    if(messages.length >0){
      copy_clip(messages);
    }else{
      alert("至少选择一项！");
    }
  }


  // 修改所选项的有效期
  function extend_time(){
    var p=<%=params[:page].to_i%>;
    if(p==0){p=1;}
    var checked_arrays = checked_item_ids(".check_boxes");
    var t = $("#time-field").attr("value");
    if(t.length==4||t.length<=0){
    }else{
      if(checked_arrays.length>0){
        var pars='time='+t+"&page="+p+"&array="+checked_arrays;
        $.ajax({
           type: "POST",
           url: "/user/info_manage/extend_time",
           data: pars,
           success: function(html){
             $("#right").html(html);
           }
        });

      }else{
        alert("至少选择一项！");
      }
    }
    $("update_time").hide();
  }

  function checked_item_ids(check_boxes) {
    var checked_item_ids = [];
    $(check_boxes).each(function(i) {
      if (this.checked){
        checked_item_ids[i] = this.value;
      }
    });
    return checked_item_ids;
  }
  
  //删除所选项
  function del(){
    var p=<%=params[:page].to_i%>
    if(p==0){p=1;}
    var checked_arrays = checked_item_ids(".check_boxes");
    //params....
    if(checked_arrays.length > 0){
       var sure = window.confirm('你确定要删除么?');
       if(sure){
         var pars="array="+checked_arrays+"&page="+p;
         $.ajax({
           type: "POST",
           url: "/user/info_manage/delete",
           data: pars,
           success: function(html){
             $("#right").html(html);
           }
         });
        }else {}
        
      }else{
        alert("请至少选择一项！");
      }
   }

    function copy_clip(copy){
     if (window.clipboardData){
     window.clipboardData.setData("Text", copy);}
     else if (window.netscape){
     try {
                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
             }
             catch (e)
             {
                 alert("!!被浏览器拒绝！\n请在浏览器地址栏输入’about:config’并回车\n然后将’signed.applets.codebase_principal_support’设置为’true’");
             } var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
     if (!clip) return;
     var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
     if (!trans) return;
     trans.addDataFlavor('text/unicode');
     var str = new Object();
     var len = new Object();
     var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
     var copytext=copy;
     str.data=copytext;
     trans.setTransferData("text/unicode",str,copytext.length*2);
     var clipid=Components.interfaces.nsIClipboard;
     if (!clip) return false;
     clip.setData(trans,null,clipid.kGlobalClipboard);}
     alert("已复制"+copy);
     return false;
     }

     
    function select_all(o){
      $(".check_boxes").each(function(i){
        this.checked = o.checked;
      }); 
    }

</script>

  <script type="text/javascript">
    jQuery("#survey-selector-a").multiSelect(
      {
        showHeader: false,
        maxHeight: 200,
        minWidth: 140,
        noneSelectedText: '指定可用量表',
        selectedText: function(numChecked, numTotal, checkedItems){
          return '选定了' + numChecked + "个";
        }

      }
    );

    jQuery("#survey-selector-b").multiSelect(
      {
        showHeader: false,
        shadow:true,
        maxHeight: 200,
        minWidth: 140,
        noneSelectedText: '指定可用量表',
        selectedText: function(numChecked, numTotal, checkedItems){
          return '选定了' + numChecked + "个";
        }

      }
    );
      
    function show_update(){
      $("#update_time").show();
    }
  </script>
</body>
</html>
